# -*- coding:utf-8 -*-
# time: 2025/8/1 ♡  15:05
# author:张伟
from apps.front.forms import BaseForm
from wtforms import FileField, StringField, IntegerField
from wtforms.validators import InputRequired, Length, Regexp, NumberRange, Email
from flask_wtf.file import FileAllowed, FileSize


class UploadImageForm(BaseForm):
    image = FileField(
        validators=[InputRequired(message="请上传图片！"), FileAllowed(["jpg", "jpeg", "png"], message="上传的图片格式不正确！"),
                    FileSize(1024 * 1024 * 5, message="上传的图片不能超过5M！")])


class AddBannerForm(BaseForm):
    name = StringField(
        validators=[InputRequired(message="请输入轮播图名称！"), Length(min=2, max=20, message="轮播图名称长度必须在2-20个字符之间！")])
    image_url = StringField(validators=[InputRequired(message="请输入轮播图图片的URL！"),
                                        Regexp(r'^https?://[^\s/$.?#].[^\s]*$', message="请输入有效的HTTP/HTTPS链接！")])
    link_url = StringField(validators=[InputRequired(message="请输入轮播图跳转的URL！"),
                                       Regexp(r'^https?://[^\s/$.?#].[^\s]*$', message="请输入有效的HTTP/HTTPS链接！")])
    priority = IntegerField(validators=[InputRequired(message="请输入轮播图的优先级！")])


class EditBannnerForm(BaseForm):
    id = IntegerField(validators=[InputRequired(message="请输入轮播图ID！")])
    name = StringField(
        validators=[InputRequired(message="请输入轮播图名称！"), Length(min=2, max=20, message="轮播图名称长度必须在2-20个字符之间！")])
    image_url = StringField(validators=[InputRequired(message="请输入轮播图图片的URL！"),
                                        Regexp(r'^https?://[^\s/$.?#].[^\s]*$', message="请输入有效的HTTP/HTTPS链接！")])
    link_url = StringField(validators=[InputRequired(message="请输入轮播图跳转的URL！"),
                                       Regexp(r'^https?://[^\s/$.?#].[^\s]*$', message="请输入有效的HTTP/HTTPS链接！")])
    priority = IntegerField(validators=[InputRequired(message="请输入轮播图的优先级！")])


class AddBoardForm(BaseForm):
    name = StringField(
        validators=[InputRequired(message="请输入板块名称！"), Length(min=2, max=20, message="板块名称长度必须在2-20个字符之间！")])
    priority = IntegerField(
        validators=[InputRequired(message="请输入板块的优先级！"), NumberRange(min=1, max=5, message="板块的优先级必须在1-5之间！")])


class EditBoardForm(BaseForm):
    id = IntegerField(validators=[InputRequired(message="请输入板块ID！")])
    name = StringField(
        validators=[InputRequired(message="请输入板块名称！"), Length(min=2, max=20, message="板块名称长度必须在2-20个字符之间！")])
    priority = IntegerField(
        validators=[InputRequired(message="请输入板块的优先级！"), NumberRange(min=1, max=5, message="板块的优先级必须在1-5之间！")])

class AddStaffForm(BaseForm):
    name = StringField(
        validators=[InputRequired(message="用户名不能为空"), Length(min=3, max=20, message="用户名长度在3-20个字符之间")])
    email = StringField(validators=[InputRequired(message="邮箱不能为空"), Email(message="邮箱格式错误")])
    role = IntegerField(validators=[InputRequired(message="请传入角色ID！")])

class EditStaffForm(BaseForm):
    id = StringField(validators=[InputRequired(message="请传入员工ID！")])
    name = StringField(
        validators=[InputRequired(message="用户名不能为空"), Length(min=3, max=20, message="用户名长度在3-20个字符之间")])
    email = StringField(validators=[InputRequired(message="邮箱不能为空"), Email(message="邮箱格式错误")])
    role = IntegerField(validators=[InputRequired(message="请传入角色ID！")])
